package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Billinfo;
import com.li.drug.mapper.BillinfoMapper;
import com.li.drug.service.BillinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

@Service
    public class BillinfoServiceImpl extends ServiceImpl<BillinfoMapper, Billinfo> implements BillinfoService {

    @Autowired
    BillinfoMapper billinfoMapper;

    /**
     * 分页查询对象
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param param 查询参数
     * @return
     */
    @Override
    public Page<Billinfo> selectBillinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Billinfo> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        Page<Billinfo> page = new Page<>(pageNum,pageSize);
        return billinfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addBillinfo(Billinfo billinfo) {
        return billinfoMapper.insert(billinfo);
    }

    @Override
    public int editBillinfo(Billinfo billinfo) {
       return billinfoMapper.updateById(billinfo);
    }

    @Override
    public Billinfo getBillinfoById(Integer id) {
        return billinfoMapper.selectById(id);
    }

    @Override
    public int delBillinfoById(Integer id) {
        return billinfoMapper.deleteById(id);
    }
}
